﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using Data.Models;
using Presentation.Models;
using Presentation.ViewModels;

namespace Tests
{
    [TestFixture]
    public class AnecdotalListViewModelTests
    {
        AnecdotesViewModel _anecdotalListViewModel;

        [SetUp]
        public void Initialize()
        {
            DataModels dataModels = (new Data.Sources.Test()).GetData();
            PresentationModels presentationModels = new PresentationModels(dataModels);

            _anecdotalListViewModel = new AnecdotesViewModel(presentationModels);
        }
        
        [Test]
        public void InitializedCorrectly()
        {
            Assert.AreEqual(2, _anecdotalListViewModel.Students.Count);
            Assert.AreEqual(2, _anecdotalListViewModel.Domains.Count);
            Assert.AreEqual(2, _anecdotalListViewModel.Anecdotes.Count);

            Assert.AreEqual("", _anecdotalListViewModel.NewAnecdoteDomain);
            Assert.AreEqual("", _anecdotalListViewModel.NewAnecdoteStudent);
            Assert.AreEqual("", _anecdotalListViewModel.NewAnecdoteNote);
        }

        [Test]
        public void AddAnecdoteValidationTest()
        {
            string test = "Test";

            _anecdotalListViewModel.NewAnecdoteNote = test;
            _anecdotalListViewModel.NewAnecdoteDomain = test;
            _anecdotalListViewModel.NewAnecdoteStudent = "";

            _anecdotalListViewModel.AddNewAnecdote();

            Assert.AreEqual(2, _anecdotalListViewModel.Anecdotes.Count);

            _anecdotalListViewModel.NewAnecdoteStudent = test;
            _anecdotalListViewModel.NewAnecdoteDomain = test;
            _anecdotalListViewModel.NewAnecdoteNote = "";

            _anecdotalListViewModel.AddNewAnecdote();

            Assert.AreEqual(2, _anecdotalListViewModel.Anecdotes.Count);

            _anecdotalListViewModel.NewAnecdoteNote = test;
            _anecdotalListViewModel.NewAnecdoteStudent = test;
            _anecdotalListViewModel.NewAnecdoteDomain = "";

            _anecdotalListViewModel.AddNewAnecdote();

            Assert.AreEqual(2, _anecdotalListViewModel.Anecdotes.Count);
        }

        [Test]
        public void AddAnecdoteTest()
        {
            string test = "test";

            _anecdotalListViewModel.NewAnecdoteNote = test;
            _anecdotalListViewModel.NewAnecdoteStudent = test;
            _anecdotalListViewModel.NewAnecdoteDomain = test;

            _anecdotalListViewModel.AddNewAnecdote();

            Assert.AreEqual(3, _anecdotalListViewModel.Anecdotes.Count);
            Assert.AreEqual(3, _anecdotalListViewModel.Domains.Count);
            Assert.AreEqual(3, _anecdotalListViewModel.Students.Count);

        }

        [Test]
        public void RemoveAnecdoteTest()
        {
            _anecdotalListViewModel.RemoveAnecdote(_anecdotalListViewModel.Anecdotes[0]);

            Assert.AreEqual(1, _anecdotalListViewModel.Anecdotes.Count);
            Assert.AreEqual(1, _anecdotalListViewModel.Domains.Count);
            Assert.AreEqual(1, _anecdotalListViewModel.Students.Count);
        }

        [Test]
        public void RemoveAllAnecdotesTest()
        {
            _anecdotalListViewModel.RemoveAnecdote(_anecdotalListViewModel.Anecdotes[0]);
            _anecdotalListViewModel.RemoveAnecdote(_anecdotalListViewModel.Anecdotes[0]);

            Assert.AreEqual(0, _anecdotalListViewModel.Anecdotes.Count);
            Assert.AreEqual(0, _anecdotalListViewModel.Domains.Count);
            Assert.AreEqual(0, _anecdotalListViewModel.Students.Count);

        }

        [Test]
        public void RemoveAllAnecdotesTestAndAddTwoBackTest()
        {
            _anecdotalListViewModel.RemoveAnecdote(_anecdotalListViewModel.Anecdotes[0]);
            _anecdotalListViewModel.RemoveAnecdote(_anecdotalListViewModel.Anecdotes[0]);

            Assert.AreEqual(0, _anecdotalListViewModel.Anecdotes.Count);
            Assert.AreEqual(0, _anecdotalListViewModel.Domains.Count);
            Assert.AreEqual(0, _anecdotalListViewModel.Students.Count);

            _anecdotalListViewModel.NewAnecdoteNote = "test";
            _anecdotalListViewModel.NewAnecdoteStudent = "test";
            _anecdotalListViewModel.NewAnecdoteDomain = "test";

            _anecdotalListViewModel.AddNewAnecdote();

            _anecdotalListViewModel.NewAnecdoteDomain = "test2";

            _anecdotalListViewModel.AddNewAnecdote();

            _anecdotalListViewModel.NewAnecdoteDomain = "test3";

            _anecdotalListViewModel.AddNewAnecdote();

            _anecdotalListViewModel.NewAnecdoteStudent = "test2";

            _anecdotalListViewModel.AddNewAnecdote();

            _anecdotalListViewModel.NewAnecdoteStudent = "test3";

            _anecdotalListViewModel.AddNewAnecdote();

            Assert.AreEqual(5, _anecdotalListViewModel.Anecdotes.Count);
        }

        [Test]
        public void NewDomainsAreAddedToDomainList()
        {
            _anecdotalListViewModel.NewAnecdoteNote = "test";
            _anecdotalListViewModel.NewAnecdoteStudent = "test";
            _anecdotalListViewModel.NewAnecdoteDomain = "test";

            _anecdotalListViewModel.AddNewAnecdote();

            Assert.AreEqual(3, _anecdotalListViewModel.Domains.Count);
        }

        [Test]
        public void NewStudentsAreAddedToStudentList()
        {
            _anecdotalListViewModel.NewAnecdoteNote = "test";
            _anecdotalListViewModel.NewAnecdoteStudent = "test";
            _anecdotalListViewModel.NewAnecdoteDomain = "test";

            _anecdotalListViewModel.AddNewAnecdote();

            Assert.AreEqual(3, _anecdotalListViewModel.Students.Count);
        }

        [Test]
        public void UnusedDomainsAreRemovedFromList()
        {
            _anecdotalListViewModel.RemoveAnecdote(_anecdotalListViewModel.Anecdotes[0]);

            Assert.AreEqual(1, _anecdotalListViewModel.Domains.Count);
        }

        [Test]
        public void UnusedStudentsAreRemovedFromList()
        {
            _anecdotalListViewModel.RemoveAnecdote(_anecdotalListViewModel.Anecdotes[0]);

            Assert.AreEqual(1, _anecdotalListViewModel.Students.Count);
        }
    }


}
